package models

import "time"

// LoanOrg  上链时总、支行关系表
type LoanOrg struct {
	ID        uint32    `json:"id"         xorm:"notnull pk autoincr bigint id comment('id')"`
	OrgId     string    `json:"org_id"     xorm:"notnull default '' varchar(50) comment('总行编号')"`
	SubOrgId  string    `json:"sub_org_id" xorm:"notnull default '' varchar(50) comment('支行编号')"`
	Type      int8      `json:"type"      xorm:"notnull default 0 tinyint(3) comment('类型(0:接收;1:发送)')"`
	CreatedAt time.Time `json:"createdAt" xorm:"notnull default CURRENT_TIMESTAMP Timestamp created comment('创建时间')"`
	UpdatedAt time.Time `json:"updatedAt" xorm:"notnull default CURRENT_TIMESTAMP Timestamp updated comment('更新时间')"`
}

func (l *LoanOrg) TableName() string {
	return "loan_org"
}

type LoanOrgList []LoanOrg

func (l LoanOrgList) SubOrgIds() []string {
	temp := make([]string, 0, len(l))
	for _, v := range l {
		temp = append(temp, v.SubOrgId)
	}

	//去重
	result := make([]string, 0)
	tempMap := map[string]byte{} // 存放不重复主键
	for _, e := range temp {
		l := len(tempMap)
		tempMap[e] = 0
		if len(tempMap) != l { // 加入map后，map长度变化，则元素不重复
			result = append(result, e)
		}
	}
	return result
}
